﻿using Blog.Models.Entitys;
using Blog.Models.ReqModels;
using Blog.Models.ViewModels;
using Blog.Repository.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Service.Base
{
    public class BaseService<TEntity> : IBaseService<TEntity> where TEntity : BaseEntity, new()
    {
        protected readonly IBaseRepository<TEntity> _baseRepository;

        public BaseService(IBaseRepository<TEntity> baseRepository)
        {
            this._baseRepository = baseRepository;
        }
        public async Task<int> BatchDelete(IList<int> ids)
        {
            return await _baseRepository.BatchDelete(ids);
        }

        public async Task<IList<TEntity>> BatchInsert(IList<TEntity> entities)
        {
            await _baseRepository.BatchInsert(entities);
            return entities;
        }

        public async Task<IList<TEntity>> BatchUpdate(IList<TEntity> entities)
        {
            return await _baseRepository.BatchUpdate(entities);
        }

        public async Task<int> Delete(int id)
        {
            return await _baseRepository.Delete(id);
        }

        public async Task<TEntity> Insert(TEntity entity)
        {
            return await _baseRepository.Insert(entity);
        }

        public async Task<TEntity> Query(int id)
        {
            return await _baseRepository.Query(id);
        }

        public async Task<IList<TEntity>> Query(IList<int> ids)
        {
            return await _baseRepository.Query(ids);
        }

        public async Task<IList<TEntity>> Query()
        {
            return await _baseRepository.Query();
        }

        public async Task<IList<TEntity>> Query(Expression<Func<TEntity, bool>> expression)
        {
            return await _baseRepository.Query(expression);
        }

        public async Task<PageList<TEntity>> QueryPage<TQuery>(TQuery query) where TQuery : BaseQuery
        {
            return await _baseRepository.QueryPage(null, query.PageIndex, query.PageSize);
        }

        public async Task<TEntity> Update(TEntity entity)
        {
            return await _baseRepository.Update(entity);
        }
    }
}
